//package com.xspace.android.xafcommon.util;
//
//import java.util.HashSet;
//import java.util.Set;
//import java.util.Vector;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//import android.content.ContentResolver;
//import android.content.ContentValues;
//import android.content.Context;
//import android.database.Cursor;
//import android.net.Uri;
//import android.provider.BaseColumns;
//import android.text.TextUtils;
//import android.util.Log;
//import android.util.Patterns;
//
//public class Telephony {
//	public final static class Sms {
//
//		public static final Uri CONTENT_URI = Uri.parse("content://sms");
//
//		public static final int READ_STATUS = 1;
//		public static final int UNREAD_STATUS = 0;
//
//		public static final String _ID = "_id";
//		public static final String PROTOCOL = "protocol";
//		public static final String ADDRESS = "address";
//		public static final String DATE = "date";
//		public static final String BODY = "body";
//		public static final String PERSON = "person";
//		public static final String THREAD_ID = "thread_id";
//		public static final String STATUS = "status";
//		public static final String LOCKED = "locked";
//		public static final String READ = "read";
//		public static final String TYPE = "type";
//		public static final String SUBJECT = "subject";
//
//		public static String DEFAULT_SORT_ORDER = "date DESC";
//
//		public static final int MESSAGE_TYPE_ALL = 0;
//		public static final int MESSAGE_TYPE_INBOX = 1;
//		public static final int MESSAGE_TYPE_SENT = 2;
//		public static final int MESSAGE_TYPE_DRAFT = 3;
//		public static final int MESSAGE_TYPE_OUTBOX = 4;
//		public static final int MESSAGE_TYPE_FAILED = 5;
//		public static final int MESSAGE_TYPE_QUEUED = 6;
//
//		public static final int STATUS_PENDING = 64;
//		public static long STATUS_NONE = -1;
//		public static final int STATUS_COMPLETE = 0;
//		public static final int STATUS_FAILED = 128;
//
//		public static Uri addMessageToUri(ContentResolver resolver, Uri uri,
//				String address, String body, String subject, Long date,
//				boolean read, boolean deliveryReport) {
//			return addMessageToUri(resolver, uri, address, body, subject, date,
//					read, deliveryReport, -1L);
//		}
//
//		public static Uri addMessageToUri(ContentResolver resolver, Uri uri,
//				String address, String body, String subject, Long date,
//				boolean read, boolean deliveryReport, long threadId) {
//			ContentValues values = new ContentValues(7);
//
//			values.put(ADDRESS, address);
//			if (date != null) {
//				values.put(DATE, date);
//			}
//			values.put(READ, read ? Integer.valueOf(1) : Integer.valueOf(0));
//			values.put(SUBJECT, subject);
//			values.put(BODY, body);
//			if (deliveryReport) {
//				values.put(STATUS, STATUS_PENDING);
//			}
//			if (threadId != -1L) {
//				values.put(THREAD_ID, threadId);
//			}
//			return resolver.insert(uri, values);
//		}
//
//		public final static class Conversations {
//			public static final Uri CONTENT_URI = Uri
//					.parse("content://sms/conversations");
//
//			public final static String THREAD_ID = "thread_id";
//
//			public static final String DEFAULT_SORT_ORDER = "date desc";
//
//			public static final String REPLY_PATH_PRESENT = "reply_path_present";
//
//			public static final String SERVICE_CENTER = "service_center";
//
//		}
//
//		public static class Sent {
//			public static final Uri CONTENT_URI = Uri
//					.parse("content://sms/sent");
//
//			public static Uri addMessage(ContentResolver resolver,
//					String address, String body, String subject, Long date) {
//				return addMessageToUri(resolver, CONTENT_URI, address, body,
//						subject, date, true, false);
//			}
//
//		}
//
//		public static boolean isOutgoingFolder(int messageType) {
//			return ((messageType == MESSAGE_TYPE_FAILED)
//					|| (messageType == MESSAGE_TYPE_OUTBOX)
//					|| (messageType == MESSAGE_TYPE_SENT) || (messageType == MESSAGE_TYPE_QUEUED));
//		}
//	}
//
//	public final static class MmsSms {
//		public static final Uri CONTENT_URI = Uri
//				.parse("content://mms-sms/conversations");
//		public static final Uri CONTENT_DRAFT_URI = Uri
//				.parse("content://mms-sms/draft");
//		public static final Uri CONTENT_LOCKED_URI = Uri
//				.parse("content://mms-sms/locked");
//		public static final Uri SEARCH_URI = Uri
//				.parse("content://mms-sms/search");
//		public static final String TYPE_DISCRIMINATOR_COLUMN = "transport_type";
//		public static final int ERR_TYPE_GENERIC_PERMANENT = 10;
//		public static final int ERR_TYPE_GENERIC = 1;
//		public static final int NO_ERROR = 0;
//
//		public static final String[] PROJECTION = new String[] {
//				"transport_type",
//				"_id",
//				"thread_id",
//				// For SMS
//				Sms.ADDRESS, Sms.BODY, Sms.DATE, Sms.READ,
//				Sms.TYPE,
//				Sms.STATUS,
//				Sms.LOCKED,
//				// For MMS
//				Mms.SUBJECT, Mms.SUBJECT_CHARSET, Mms.DATE, Mms.READ,
//				Mms.MESSAGE_TYPE, Mms.MESSAGE_BOX, Mms.DELIVERY_REPORT,
//				Mms.READ_REPORT, PendingMessages.ERROR_TYPE, Mms.LOCKED,
//				Sms.SUBJECT };
//
//	}
//
//	public final static class Mms implements BaseColumns {
//		public static final Uri CONTENT_URI = Uri.parse("content://mms");
//
//		public static final int MESSAGE_BOX_ALL = 0;
//		public static final int MESSAGE_BOX_INBOX = 1;
//		public static final int MESSAGE_BOX_SENT = 2;
//		public static final int MESSAGE_BOX_DRAFTS = 3;
//		public static final int MESSAGE_BOX_OUTBOX = 4;
//		public static final String THREAD_ID = "thread_id";
//		public static final String RETRIEVE_TEXT = "retr_txt";
//		public static final String CONTENT_LOCATION = "ct_l";
//		public static final String CONTENT_TYPE = "ct_t";
//		public static final String MESSAGE_CLASS = "m_cls";
//		public static final String MESSAGE_ID = "m_id";
//		public static final String RESPONSE_TEXT = "resp_txt";
//		public static final String TRANSACTION_ID = "tr_id";
//		public static final String CONTENT_CLASS = "ct_cls";
//		public static final String MMS_VERSION = "v";
//		public static final String PRIORITY = "pri";
//		public static final String READ_STATUS = "read_status";
//		public static final String REPORT_ALLOWED = "rpt_a";
//		public static final String RETRIEVE_STATUS = "retr_st";
//		public static final String STATUS = "st";
//		public static final String DELIVERY_TIME = "d_tm";
//		public static final String EXPIRY = "exp";
//		public static final String MESSAGE_SIZE = "m_size";
//		public static final String RETRIEVE_TEXT_CHARSET = "retr_txt_cs";
//		public static final String SUBJECT = "sub";
//		public static final String SUBJECT_CHARSET = "sub_cs";
//		public static final String DATE = "date";
//		public static final String READ = "read";
//		public static final String MESSAGE_TYPE = "m_type";
//		public static final String MESSAGE_BOX = "msg_box";
//		public static final String DELIVERY_REPORT = "d_rpt";
//		public static final String READ_REPORT = "rr";
//		public static final String LOCKED = "locked";
//
//		public static final String[] PDU_PROJECTION = new String[] { _ID,
//				MESSAGE_BOX, THREAD_ID, RETRIEVE_TEXT, SUBJECT,
//				CONTENT_LOCATION, CONTENT_TYPE, MESSAGE_CLASS, MESSAGE_ID,
//				RESPONSE_TEXT, TRANSACTION_ID, CONTENT_CLASS, DELIVERY_REPORT,
//				MESSAGE_TYPE, MMS_VERSION, PRIORITY, READ_REPORT, READ_STATUS,
//				REPORT_ALLOWED, RETRIEVE_STATUS, STATUS, DATE, DELIVERY_TIME,
//				EXPIRY, MESSAGE_SIZE, SUBJECT_CHARSET, RETRIEVE_TEXT_CHARSET };
//
//	}
//
//	public final static class Threads implements BaseColumns {
//		public static final Uri CONTENT_URI = Uri
//				.parse("content://mms-sms/conversations");
//		public static final Uri sAllThreadsUri = CONTENT_URI.buildUpon()
//				.appendQueryParameter("simple", "true").build();
//
//		private static final Uri THREAD_ID_CONTENT_URI = Uri
//				.parse("content://mms-sms/threadID");
//		public static final Uri OBSOLETE_THREADS_URI = Uri.withAppendedPath(
//				CONTENT_URI, "obsolete");
//		public static final Pattern NAME_ADDR_EMAIL_PATTERN = Pattern
//				.compile("\\s*(\"[^\"]*\"|[^<>\"]+)\\s*<([^<>]+)>\\s*");
//
//		public static final String DATE = "date";
//		public static final String MESSAGE_COUNT = "message_count";
//		public static final String RECIPIENT_IDS = "recipient_ids";
//		public static final String ERROR = "error";
//		public static final String READ = "read";
//		public static final String SNIPPET_CHARSET = "snippet_cs";
//		public static final String SNIPPET = "snippet";
//		public static final String HAS_ATTACHMENT = "has_attachment";
//
//		public static final String[] ALL_THREADS_PROJECTION = { Threads._ID,
//				Threads.DATE, Threads.MESSAGE_COUNT, Threads.RECIPIENT_IDS,
//				Threads.SNIPPET, Threads.SNIPPET_CHARSET, Threads.READ,
//				Threads.ERROR, Threads.HAS_ATTACHMENT };
//		public static final String DEFAULT_SORT_ORDER = "date desc";
//
//		public static final int INDEX_ID = 0;
//		public static final int INDEX_DATE = 1;
//		public static final int INDEX_MESSAGE_COUNT = 2;
//		public static final int INDEX_RECIPIENT_IDS = 3;
//		public static final int INDEX_SNIPPET = 4;
//		public static final int INDEX_SNIPPET_CS = 5;
//		public static final int INDEX_READ = 6;
//		public static final int INDEX_ERROR = 7;
//		public static final int INDEX_HAS_ATTACHMENT = 8;
//
//		/**
//		 * This is a single-recipient version of getOrCreateThreadId. It's
//		 * convenient for use with SMS messages.
//		 */
//		public static long getOrCreateThreadId(Context context, String recipient) {
//			Set<String> recipients = new HashSet<String>();
//
//			recipients.add(recipient);
//			return getOrCreateThreadId(context, recipients);
//		}
//
//		/**
//		 * Given the recipients list and subject of an unsaved message, return
//		 * its thread ID. If the message starts a new thread, allocate a new
//		 * thread ID. Otherwise, use the appropriate existing thread ID.
//		 *
//		 * Find the thread ID of the same set of recipients (in any order,
//		 * without any additions). If one is found, return it. Otherwise, return
//		 * a unique thread ID.
//		 */
//		public static long getOrCreateThreadId(Context context,
//				Set<String> recipients) {
//			Uri.Builder uriBuilder = THREAD_ID_CONTENT_URI.buildUpon();
//
//			for (String recipient : recipients) {
//				if (isEmailAddress(recipient)) {
//					recipient = extractAddrSpec(recipient);
//				}
//
//				uriBuilder.appendQueryParameter("recipient", recipient);
//			}
//
//			Uri uri = uriBuilder.build();
//			// if (DEBUG) Log.v(TAG, "getOrCreateThreadId uri: " + uri);
//
//			Cursor cursor = context.getContentResolver().query(uri,
//					new String[] { BaseColumns._ID }, null, null, null);
//			if (true) {
//				Log.v("Threads",
//						"getOrCreateThreadId cursor cnt: " + cursor.getCount());
//			}
//			if (cursor != null) {
//				try {
//					if (cursor.moveToFirst()) {
//						return cursor.getLong(0);
//					} else {
//						Log.e("Threads",
//								"getOrCreateThreadId returned no rows!");
//					}
//				} finally {
//					cursor.close();
//				}
//			}
//
//			Log.e("Threads",
//					"getOrCreateThreadId failed with uri " + uri.toString());
//			throw new IllegalArgumentException(
//					"Unable to find or allocate a thread ID.");
//		}
//
//		public static String extractAddrSpec(String address) {
//			Matcher match = NAME_ADDR_EMAIL_PATTERN.matcher(address);
//
//			if (match.matches()) {
//				return match.group(2);
//			}
//			return address;
//		}
//
//		/**
//		 * Returns true if the address is an email address
//		 *
//		 * @param address
//		 *            the input address to be tested
//		 * @return true if address is an email address
//		 */
//		public static boolean isEmailAddress(String address) {
//			if (TextUtils.isEmpty(address)) {
//				return false;
//			}
//
//			String s = extractAddrSpec(address);
//			Matcher match = Patterns.EMAIL_ADDRESS.matcher(s);
//			return match.matches();
//		}
//	}
//
//	public static final class CanonicalAddresses implements BaseColumns {
//
//		public static final String ADDRESS = "address";
//
//		// private static void Test(Context context) {
//		// Cursor c = context.getContentResolver().query(
//		// Uri.parse("content://mms-sms/messages/byphone/" + "18611575358"),
//		// new String[]{"thread_id", "address"}, null, null, null);
//		// if (c != null && c.moveToFirst()) {
//		// do {
//		// int cCount = c.getColumnCount();
//		// for (int i = 0; i < cCount; i++) {
//		// String cName = c.getColumnName(i);
//		// String value = c.getString(c.getColumnIndex(cName));
//		// System.out.println("cname:" + cName + "===value:"
//		// + value);
//		// }
//		// } while (c.moveToNext());
//		// }
//		// c.close();
//		// }
//
//		public static final Vector<String> fetchPhoneNumber(Context context,
//				String recipientIds) {
//			String[] recipientIdArr = recipientIds.split(" ");
//			Vector<String> phoneNumberVec = new Vector<String>();
//			Cursor c = null;
//			for (int i = 0; i < recipientIdArr.length; i++) {
//				String phoneNumber = "";
//				String recipientId = recipientIdArr[i];
//				c = context.getContentResolver().query(
//						Uri.parse("content://mms-sms/canonical-address/"
//								+ recipientId), null, null, null, null);
//				if (c.moveToFirst()) {
//					do {
//						phoneNumber = AppUtils.getParseredPhoneNum(c.getString(c
//								.getColumnIndex("address")));
//						break;
//					} while (c.moveToNext());
//				}
//				if (!phoneNumberVec.contains(phoneNumber)) {
//					phoneNumberVec.add(phoneNumber);
//				}
//				c.close();
//			}
//
//			return phoneNumberVec;
//		}
//
//	}
//
//	public static final class PendingMessages implements BaseColumns {
//		public static final String ERROR_TYPE = "err_type";
//		public static final String MSG_TYPE = "msg_type";
//		public static final String MSG_ID = "msg_id";
//		public static final Uri CONTENT_URI = Uri
//				.parse("content://mms-sms/pending");
//		public static final String RETRY_INDEX = "retry_index";
//		public static final String DUE_TIME = "due_time";
//		public static final String LAST_TRY = "last_try";
//
//	}
//}
